<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <link rel="shortcut icon" href="logo.png" type="image/x-icon"/>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/global.css">
    <link rel="stylesheet" href="css/home_v3.css"/>
</head>
<body>

<div class="wrap clear news_content" id="main">
    <!--左边-->
    <div class="left left-box">
        <!--banner-->
        <div class="yhome-banner">
            <a href="" class="yhb-big left">
                <i>行业</i>
                <img src="http://p9.pstatp.com/list/640x360/2ecd00018d26750870f3" alt="">
                <span class="over">网红“什么七七”清纯美照，清新可人er</span>
            </a>
            <a href="" class="yhb-small right">
                <i>娱乐</i>
                <img src="http://p1.pstatp.com/list/272x178/2edc000214935e8e9a5a" alt="">
                <span class="over">古筝女主播大汇总</span>
            </a>
            <a href="" class="yhb-small yhb-small2 right">
                <i>视频</i>
                <img src="http://p3.pstatp.com/list/272x178/2ece0000dbdbfbd7dd46" alt="">
                <span class="over">直击撒贝宁和妻子的甜蜜爱情，一路被祝福</span>
            </a>
        </div>
        <!--新闻-->
        <div id="home-list">
            <div class="tab-bar">
                <ul class="clear">
                    <li class="active"><a href="javascript:void(0);">全&nbsp;&nbsp;部</a></li>
                    <li><a href="javascript:void(0);">资&nbsp;&nbsp;讯</a></li>
                    <li><a href="javascript:void(0);">行&nbsp;&nbsp;业</a></li>
                    <li><a href="javascript:void(0);">图&nbsp;&nbsp;集</a></li>
                    <li><a href="javascript:void(0);">视&nbsp;&nbsp;频</a></li>
                    <li><a href="javascript:void(0);">游&nbsp;&nbsp;戏</a></li>
                </ul>
            </div>
            <div class="list-main">
            </div>
        </div>
    </div>
</div>
<!--全部-->
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/dropload.min.js"></script>
<script type="text/javascript">
    $(function () {
        // 页数
        var page = 1;
        var itemIndex = 0;
        var tab1LoadEnd = false;
        var tab2LoadEnd = false;
        var tab3LoadEnd = false;
        var tab4LoadEnd = false;
        var tab5LoadEnd = false;
        var tab6LoadEnd = false;
        var page1 = 1;
        var page2 = 1;
        var page3 = 1;
        var page4 = 1;
        var page5 = 1;
        var page6 = 1;
        //下拉加载
        var dropload = $('#home-list').dropload({
            scrollArea: window,
            domDown: {
                domClass: 'list-loading',
                domRefresh: '<img src="images/loading.gif" alt="正在加载中"> 正在加载中',
                domLoad: '<img src="images/loading.gif" alt="正在加载中"> 正在加载中',
                domNoData: '<p class="list-loading">暂无数据</p>'
            },
            loadDownFn: function (me) {
                if (itemIndex == '0') {
                    // 全部
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/200/article/rand/1?page=' + page1,
                        dataType: 'json',
                        success: function (data) {
                            var result = '';
                            page1++;
                            //加载数据
                            result = dataHtml(data, me);
                            if (result == '') {
                                // 数据加载完
                                tab1LoadEnd = true;
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 为了测试，延迟1秒加载
                            setTimeout(function () {
                                $('.list-main').eq(0).append(result);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (itemIndex == '1') {
                    //资讯
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/201/article/rand/1?page=' + page2,
                        dataType: 'json',
                        success: function (data) {
                            var result = '';
                            page2++;
                            //加载数据
                            result = dataHtml(data, me);
                            if (result == '') {
                                // 数据加载完
                                tab2LoadEnd = true;
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 为了测试，延迟1秒加载
                            setTimeout(function () {
                                $('.list-main').eq(1).append(result);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (itemIndex == '2') {
                    //行业
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/202/article/rand/1?page=' + page3,
                        dataType: 'json',
                        success: function (data) {
                            var result = '';
                            page3++;
                            //加载数据
                            result = dataHtml(data, me);
                            if (result == '') {
                                // 数据加载完
                                tab3LoadEnd = true;
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 为了测试，延迟1秒加载
                            setTimeout(function () {
                                $('.list-main').eq(2).append(result);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (itemIndex == '3') {
                    //图集
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/203/article/rand/1?page=' + page4,
                        dataType: 'json',
                        success: function (data) {
                            var result = '';
                            page4++;
                            //加载数据
                            result = dataHtml(data, me);
                            if (result == '') {
                                // 数据加载完
                                tab4LoadEnd = true;
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 为了测试，延迟1秒加载
                            setTimeout(function () {
                                $('.list-main').eq(3).append(result);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (itemIndex == '4') {
                    ///视频
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/204/article/rand/1?page=' + page6,
                        dataType: 'json',
                        success: function (data) {
                            var result = '';
                            page6++;
                            //加载数据
                            result = dataHtml(data, me);
                            if (result == '') {
                                // 数据加载完
                                tab6LoadEnd = true;
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 为了测试，延迟1秒加载
                            setTimeout(function () {
                                $('.list-main').eq(4).append(result);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (itemIndex == '5') {
                    //游戏
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/205/article/rand/1?page=' + page5,
                        dataType: 'json',
                        success: function (data) {
                            var result = '';
                            page5++;
                            //加载数据
                            result = dataHtml(data, me);
                            if (result == '') {
                                // 数据加载完
                                tab5LoadEnd = true;
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 为了测试，延迟1秒加载
                            setTimeout(function () {
                                $('.list-main').eq(5).append(result);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                }
            }
        });
        dropload.search();
    });
    function dataHtml(data,me) {
        // 拼接HTML
        var result = '';
        var arrLen = data.data.length;
        var article = data.data;
        if(arrLen>0){
            for (var i = 0; i < arrLen; i++) {
                if (article[i].type == 4 || article[i].type == 5 || article[i].type == 10) {
                    result += ' <div class="news-item clear">' +
                        '<div class="left video-lcover">' +
                        '<a href="/video/' + article[i].id + '.html" target="_blank"> <img class="cover-inner" src="' + article[i].cover + '" alt="">' +
                        '<img class="play-icon" src="../images/home2/play-icon.png" alt=""> </a> </div>' +
                        '<div class="right news-rbox normal">' +
                        '<div class="rbox-inner">' +
                        '<h3><a href="/video/' + article[i].id + '.html" target="_blank">' + article[i].title + '</a></h3>' +
                        '<p>' +
                        '<img class="u-avatar" src="' + article[i].user.data.avator + '" alt="骑驴找狒狒 ">' +
                        '<span class="u-name">' + article[i].user.data.username + '</span> <b></b>' +
                        '<img class="view-count" src="../images/home2/play_count.png" alt="播放量">' +
                        '<span>' + article[i].view_count + '</span>' +
                        '</p> </div> </div> </div>';
                } else if (article[i].type == 1 && article[i].pictures_count > 3) {
                    <!--图集四张图-->
                    result += '<div class="news-item clear">' +
                        '<div class="normal pic-news">' +
                        '<h3><a href="/news/' + article[i].id + '.html" class="img-wrap" target="_blank">' + article[i].title + '</a></h3>' +
                        '<div class="img-list clear">' +
                        '<div class="img-list-inner">';
                    var count = 1;
                    $.each(article[i].pictures, function (key, value) {
                        if (count < 5) {
                            result += '<a href="/news/' + article[i].id + '.html" class="img-wrap" target="_blank"><img src="' + replaceImageSuffix(value.src) + '" alt=""></a>';
                            count++;
                        } else {
                            return false
                        }
                    })
                    result += '</div> </div> <p>' +
                        '<img class="u-avatar" src="' + article[i].user.data.avator + '"alt="xbjiana">' +
                        '<span class="u-name">' + article[i].user.data.username + '</span> <b></b>' +
                        '<img class="view-count" src="../images/home2/view_count.png"alt="访问量">' +
                        '<span>' + article[i].view_count + '</span>' +
                        '</p> </div> </div>';
                } else if (article[i].type == 1 && article[i].pictures_count < 4 && article[i].pictures_count > 1) {
                    <!--图集一张图-->
                    result += '<div class="news-item clear">' +
                        '<div class="left news-lcover">' +
                        '<a href="/news/' + article[i].id + '.html" target="_blank"><img  src="' + replaceImageSuffix(article[i].cover) + '" alt=""></a>' +
                        '</div>' +
                        '<div class="right news-rbox normal">' +
                        '<div class="rbox-inner">' +
                        ' <h3><a href="/news/' + article[i].id + '.html" target="_blank">' + article[i].title + '</a></h3>' +
                        '<p>' +
                        '<img class="u-avatar" src="' + article[i].user.data.avator + '" alt=" 周周">' +
                        '<span class="u-name"> ' + article[i].user.data.username + '</span>' +
                        '<b></b>' +
                        '<img class="view-count" src="../images/home2/view_count.png" alt="访问量">' +
                        '<span>' + article[i].view_count + '</span>' +
                        '</p>' +
                        '</div>' +
                        '</div>' +
                        '</div>';
                }
                else {
                    if (article[i].list_cover.length == 0) {
                        <!--新闻无图-->
                        result += ' <div class="news-item clear">' +
                            '<div class="no-cover normal">' +
                            '<h3><a href="/news/' + article[i].id + '.html" target="_blank">' + article[i].title + '</a></h3>' +
                            '<p>' +
                            '<img class="u-avatar"src="' + article[i].user.data.avator + '" alt="xbnanyi ">' +
                            '<span class="u-name">' + article[i].user.data.username + '</span>' +
                            '<b></b>' +
                            '<img class="view-count" src="../images/home2/view_count.png" alt="访问量">' +
                            '<span>' + article[i].view_count + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div>';
                    } else if (article[i].list_cover.length > 0 && article[i].list_cover.length < 4) {
                        <!--新闻一张图-->
                        result += '<div class="news-item clear">' +
                            '<div class="left news-lcover">' +
                            '<a href="/news/' + article[i].id + '.html" target="_blank"><img  src="' + replaceImageSuffix(article[i].cover) + '" alt=""></a>' +
                            '</div>' +
                            '<div class="right news-rbox normal">' +
                            '<div class="rbox-inner">' +
                            ' <h3><a href="/news/' + article[i].id + '.html" target="_blank">' + cutString(article[i].title,100) + '</a></h3>' +
                            '<p>' +
                            '<img class="u-avatar" src="' + article[i].user.data.avator + '" alt=" 周周">' +
                            '<span class="u-name"> ' + article[i].user.data.username + '</span>' +
                            '<b></b>' +
                            '<img class="view-count" src="../images/home2/view_count.png" alt="访问量">' +
                            '<span>' + article[i].view_count + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div>' +
                            '</div>';
                    } else if (article[i].list_cover.length >= 4) {
                        <!--新闻四张图-->
                        result += '<div class="news-item clear">' +
                            '<div class="normal pic-news">' +
                            '<h3><a href="/news/' + article[i].id + '.html" target="_blank">' + article[i].title + '</a></h3>' +
                            '<div class="img-list clear">' +
                            '<div class="img-list-inner">' +
                            '<a href="/news/' + article[i].id + '.html" class="img-wrap" target="_blank"><img src="' + replaceImageSuffix(article[i].list_cover[0].cover) + '" ></a>' +
                            '<a href="/news/' + article[i].id + '.html" class="img-wrap" target="_blank"><img src="' + replaceImageSuffix(article[i].list_cover[1].cover) + '" ></a>' +
                            '<a href="/news/' + article[i].id + '.html" class="img-wrap" target="_blank"><img src="' + replaceImageSuffix(article[i].list_cover[2].cover) + '" ></a>' +
                            '<a href="/news/' + article[i].id + '.html" class="img-wrap" target="_blank"><img src="' + replaceImageSuffix(article[i].list_cover[3].cover) + '" ></a>' +
                            '</div> </div> <p>' +
                            '<img class="u-avatar" src="' + article[i].user.data.avator + '"alt="xbjiana">' +
                            '<span class="u-name">' + article[i].user.data.username + '</span> <b></b>' +
                            '<img class="view-count" src="../images/home2/view_count.png"alt="访问量">' +
                            '<span>' + article[i].view_count + '</span>' +
                            '</p> </div> </div>';
                    }
                }
            }
        }
        return result;
    }
    //***字数控制*************************************************
    function cutString(str,len) {
        //length属性读出来的汉字长度为1
        if (str.length * 2 <= len) {
            return str
        }
        var strlen = 0
        var s = ""
        for (var i = 0; i < str.length; i++) {
            s = s + str.charAt(i)
            if (str.charCodeAt(i) > 128) {
                strlen = strlen + 2
                if (strlen >= len) {
                    return s.substring(0, s.length - 1) + "…"
                }
            } else {
                strlen = strlen + 1
                if (strlen >= len) {
                    return s.substring(0, s.length - 2) + "…"
                }
            }
        }
        return s
    }
    //替换图片后缀
    function replaceImageSuffix(cover) {
        if(cover.indexOf("-app.thumbnail")>0){
            return cover.replace("-app.thumbnail","-web.thum");
        }else{
            return cover+'-web.thum';
        }
    }
</script>
</body>
</html>